package cn.stalk.compare.map;

import cn.stalk.compare.DataAccessor;
import cn.stalk.compare.DataComparator;

import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

/**
 * Map类数据比较器
 */
public class MapComparator extends DataComparator<Map<String, Object>> {

    public MapComparator(String[] keyFields, String[] dataFields) {
        setKeyFields(keyFields);
        setDataFields(dataFields);
    }

    public MapComparator() {
    }

    public void setKeyFields(String... keyFields) {
        LinkedHashSet<DataAccessor<Map<String, Object>, Object>> keyDataAccessors = new LinkedHashSet<>();
        for (String keyField : keyFields) {
            keyDataAccessors.add(new MapDataAccessor(keyField));
        }
        addKeyDataAccessors(keyDataAccessors);
    }

    public void setDataFields(String... dataFields) {
        Set<DataAccessor<Map<String, Object>, Object>> dataAccessorList = new HashSet<>();
        for (String dataField : dataFields) {
            dataAccessorList.add(new MapDataAccessor(dataField));
        }
        setDataAccessorList(dataAccessorList);
    }

}
